package ReflectionLearn.RefleDeepLearn;

import ReflectionLearn.RefleDeepLearnClass.Person;
import org.junit.jupiter.api.Test;


import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author Lenl
 * @version v1.0
 * @create 2021-06-07 20:13
 * @description 获取运行时类的父类
 *
 *
 */
public class ParentTest {
    /**
     * 获取运行时类的父类
     */
    @Test
    public void test(){
        Class clazz= Person.class;

        Class superclass=clazz.getSuperclass();
        System.out.println(superclass);
    }
    /**
     * 获取运行时类的带泛型的父类
     */
    @Test
    public  void test1(){
        Class clazz= Person.class;

        Type genericsuperclass=clazz.getGenericSuperclass();
        System.out.println(genericsuperclass);
    }
    /**
     * 获取运行时类的带泛型的父类的泛型
     */
    @Test
    public  void test2(){
        Class clazz= Person.class;

        Type genericsuperclass=clazz.getGenericSuperclass();
        ParameterizedType paramType=(ParameterizedType)genericsuperclass;
        //获取泛型类型
        Type[] actualTypeArguments=paramType.getActualTypeArguments();
        System.out.println(actualTypeArguments[0]);
        System.out.println(((Class)actualTypeArguments[0]).getName());
    }


}
